	<?php
		$id="";
		$name="";
		$access = array();
		foreach($group->result() as $row){
			$id=$row->group_id;
			$name=$row->name;
			$temp = json_decode($row->access,TRUE);
			if(is_array($temp))
				$access = $temp;
		}
		
		if($id == "")
			redirect('group');
	?>
	<!-- BEGIN PAGE -->
	<div class="page-content">
         <!-- BEGIN PAGE CONTAINER-->        
         <div class="container-fluid">
            <!-- BEGIN PAGE HEADER-->
			<div class="row-fluid">
				<div class="span12"> 
					<!-- BEGIN PAGE TITLE & BREADCRUMB-->			
					<h3 class="page-title">
						Group Access<small>pengaturan hak akses</small>
					</h3>
					<ul class="breadcrumb">
						<li>
							<i class="icon-cogs"></i>
							Pengaturan		
							<i class="icon-angle-right"></i>
						</li>
						<li>
							<a href="<?php echo base_url()?>group">Group</a>		
							<i class="icon-angle-right"></i>
						</li>
						<li>Hak Akses</li>	
					</ul>
					<!-- END PAGE TITLE & BREADCRUMB-->
				</div>
            </div>
            <!-- END PAGE HEADER-->
            <!-- BEGIN PAGE CONTENT--> 
			<form action="" method="post">
            <div class="row-fluid">
               <div class="span12">
                  <!-- BEGIN SAMPLE TABLE PORTLET-->
                  <div class="portlet box green">
                     <div class="portlet-title">
                        <div class="caption"><i class="icon-cogs"></i>Group Akses <?php echo $name?></div>
						<div class="tools">
							<button type="submit" class="btn blue"><i class="icon-ok"></i> SIMPAN</button>
							<a href="<?php echo base_url()?>group" class="btn">BATAL</a>
                        </div>
                     </div>
                     <div class="portlet-body flip-scroll">
                        <table id="table-access" class="table table-bordered table-striped table-condensed flip-content table-hover">
							<thead class="flip-content">
								<tr>
									<th align="center">Name</th>
									<th align="center">Alias</th>
									<th align="center">Parent</th>
									<th align="center">Access</th>
									<th align="center">Order</th>
									<th align="center" id="masterCh" class="ch"><input type="checkbox" name="checkbox" value="all" class="styled"></th>
								</tr>
							</thead>
                           <tbody>
                              <?php
								function menu_list($menu,$access,$root="0"){
									
									$loop=1;
									foreach($menu as $row){
										$id="";
										foreach($row as $key=>$parent){
										
											if($key == 'data'){
												$id = ($root != "0"?"$root.$loop":$loop);
												echo "<tr data-tt-id=\"$id\" ".($root != "0"?"data-tt-parent-id=\"$root\"":"").">";
													echo "<td>$parent[name]</td>";
													echo "<td>$parent[alias]</td>";
													echo "<td align='center'>$parent[parent]</td>";
													echo "<td align='center'>$parent[id_access]</td>";
													echo "<td align='center'>$parent[order]</td>";
													echo "<td class=\"chChildren\" align='center'><input type='checkbox' value='$parent[menu_id]' name='access[]' ".(in_array($parent['menu_id'],$access)?'checked="checked"':'')." class=\"styled\" /></td>";
													echo "</tr >";
											}else{
												if(count($parent) > 0){
													menu_list($parent,$access,$id);
												}
											}
										}
									}
								}
								menu_list($menu,$access);
								?>
                           </tbody>
                       </table>
                     </div>
                  </div>
                  <!-- END SAMPLE TABLE PORTLET-->
               </div>              
            </div>
			</form>
            <!-- END PAGE CONTENT-->
         </div>
         <!-- END PAGE CONTAINER-->
    </div>
    <!-- END PAGE -->
	<script>
		$(document).ready(function(){
			$("#table-access").treetable({ expandable: true });
			$("#table-access").treetable("expandAll");
			
			$("#masterCh").click(function() {
				var checkedStatus = $(this).find('span').hasClass('checked');
				$("#table-access tr .chChildren input:checkbox").each(function() {
					this.checked = checkedStatus;
					if (checkedStatus == this.checked) {
						$(this).closest('.checker > span').removeClass('checked');
					}
					if (this.checked) {
						$(this).closest('.checker > span').addClass('checked');
					}
				});
			});
		});
	</script>